#include "CPistol.h"

#define PISTOL_FILE "Pistol_30x5_1_2.png"

#define X_VERLOCITY 1.6f
#define Y_VERLOCITY 0.0f

#define LEFT 1
#define RIGHT 0

#define ANIMATION 25

CPistol::CPistol(LPD3DXSPRITE spriteHandler, float scale): Object()
{
	m_Sprite->CreateSprite(spriteHandler, PISTOL_FILE, 30, 5, 1, 2, scale, D3DCOLOR_XRGB(255, 255, 255));

	fx = X_VERLOCITY;
	fy = Y_VERLOCITY;

	mi_direction = RIGHT;
	mi_animationRate = ANIMATION;

	setRect(0);
}

CPistol::~CPistol()
{

}

void CPistol:: setDirection(int idirection)
{
	mi_direction = idirection;
	m_Sprite->SetSpriteLine(mi_direction);
}

void CPistol::Render()
{
	m_Sprite->Render(ix, iy);
}

void CPistol::Update(int deltaTime, int moveCame)
{
	ix += fx*deltaTime;
	fy += fy*deltaTime;
	DWORD now = GetTickCount();

	if (now - lastTime >= 1000/ANIMATION)
	{
		Next();
		lastTime = GetTickCount();
	}
	setRect(moveCame);
}

void CPistol::Next()
{
	m_Sprite->Next();
}

//get methods
//
bool CPistol::IsFinish()
{
	if(ix > 800)
		return true;

	return false;
	/*return (m_Sprite->GetIndex() == m_Sprite->GetPerRow());*/
}
void CPistol::setRect(int moveCame)
{
	m_ObRect = new RECT();
	m_ObRect->left = ix + moveCame;
	m_ObRect->right = m_ObRect->left + 60;
	m_ObRect->top = 415;
	m_ObRect->bottom = m_ObRect->top + 10;
}